﻿package net.wangit.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SessionUtil {

	public SessionUtil() {
	}

	public static final String getSession(HttpServletRequest request,
			String name, String defaultValue) {
		HttpSession session = request.getSession(true);
		String result = (String) session.getAttribute(name);
		return result != null ? result : defaultValue;
	}

	public static final boolean setSession(HttpServletRequest request,
			String name, String value) {
		HttpSession session = request.getSession(true);
		if (name != null && value != null) {
			session.setAttribute(name, value);
			return true;
		} else {
			return false;
		}
	}

	public static final String getSessionId(HttpServletRequest request) {
		HttpSession session = request.getSession(true);
		return session.getId();
	}

	public static final void setSessionTime(
			HttpServletRequest httpservletrequest, int i) {
	}

	public static final void removeSession(HttpServletRequest request,
			String name) {
		HttpSession session = request.getSession(true);
		session.removeAttribute(name);
	}

	public static final void invalidate(HttpServletRequest request) {
		HttpSession session = request.getSession(true);
		session.invalidate();
	}
}
